﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using CC.Yacht.Interfaces;

namespace CC.Yacht.Windows.Forms
{
    public partial class ScorecardTabPage : TabPage, IScorecard
    {
        #region Constructor
        public ScorecardTabPage()
        {
            InitializeComponent();

            // NOTE: Using a hack to get the control to appear transparent. 
            Controls.Add(_ScorecardPanel);
        }

        public ScorecardTabPage(User user) : this()
        {
            User = user;
        }
        #endregion

        #region Public Events
        public event EventHandler<ScoreChangedEventArgs> Changed;
        #endregion

        #region Private Event Handlers
        private void _ScorecardPanel_Changed(object sender, ScoreChangedEventArgs e)
        {
            OnChanged(e);
        }
        #endregion

        #region Protected Methods
        protected void OnChanged(ScoreChangedEventArgs eventArgs)
        {
            if (Changed != null)
            {
                Changed(this, eventArgs);
            }
        }
        #endregion

        #region Public Methods
        public void ClearDice()
        {
            _ScorecardPanel.ClearDice();
        }

        public void UpdateDice(Dice dice)
        {
            _ScorecardPanel.UpdateDice(dice);
        }

        public void UpdateScore(Scorecard scorecard)
        {
            _ScorecardPanel.UpdateScore(scorecard);
        }
        #endregion

        #region IScorecard Members
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Aces
        {
            get { return _ScorecardPanel.Aces; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Twos
        {
            get { return _ScorecardPanel.Twos; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Threes
        {
            get { return _ScorecardPanel.Threes; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Fours
        {
            get { return _ScorecardPanel.Fours; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Fives
        {
            get { return _ScorecardPanel.Fives; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Sixes
        {
            get { return _ScorecardPanel.Sixes; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int UpperSectionBonus
        {
            get { return _ScorecardPanel.UpperSectionBonus; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int UpperSectionSubtotal
        {
            get { return _ScorecardPanel.UpperSectionSubtotal; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int UpperSectionTotal
        {
            get { return _ScorecardPanel.UpperSectionTotal; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int ThreeOfAKind
        {
            get { return _ScorecardPanel.ThreeOfAKind; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int FourOfAKind
        {
            get { return _ScorecardPanel.FourOfAKind; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int FullHouse
        {
            get { return _ScorecardPanel.FullHouse; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int SmallStraight
        {
            get { return _ScorecardPanel.SmallStraight; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int LargeStraight
        {
            get { return _ScorecardPanel.LargeStraight; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Yacht
        {
            get { return _ScorecardPanel.Yacht; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Chance
        {
            get { return _ScorecardPanel.Chance; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int YachtBonuses
        {
            get { return _ScorecardPanel.YachtBonuses; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int LowerSectionTotal
        {
            get { return _ScorecardPanel.LowerSectionTotal; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Total
        {
            get { return _ScorecardPanel.Total; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public User User
        {
            get { return _ScorecardPanel.User; }
            set 
            { 
                _ScorecardPanel.User = value;

                Name = User.UserId.ToString();
                Text = User.Username; 
            }
        }

        public int GetScoreField(ScoreField scoreField)
        {
            return _ScorecardPanel.GetScoreField(scoreField);
        }

        public bool IsGameOver()
        {
            return _ScorecardPanel.IsGameOver();
        }

        public bool IsScoreFieldSet(ScoreField scoreField)
        {
            return _ScorecardPanel.IsScoreFieldSet(scoreField);
        }

        public void Reset()
        {
            _ScorecardPanel.Reset();
        }

        public bool SetScoreField(ScoreField scoreField, Dice dice)
        {
            return _ScorecardPanel.SetScoreField(scoreField, dice);
        }
        #endregion
    }
}
